package com.giantlizard.cloud.system.controller;

import com.giantlizard.cloud.base.generics.R;
import com.giantlizard.cloud.system.entity.SysRes;
import com.giantlizard.cloud.system.service.SysResService;
import com.giantlizard.cloud.system.vo.SysResVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统-资源 控制器
 */
@RestController
@RequestMapping("/res")
@Api(value = "系统-资源", tags = {"系统-资源"})
public class SysResController {

    private final SysResService sysResService;

    public SysResController(SysResService sysResService) {
        this.sysResService = sysResService;
    }

    @ApiOperation(value = "获取所有资源")
    @GetMapping("/list")
    public R<List<SysRes>> list() {
        return R.ok(sysResService.list());
    }

    @ApiOperation(value = "获取所有资源")
    @GetMapping("/tree")
    public R<List<SysResVo>> tree() {
        return R.ok(sysResService.tree());
    }

    @ApiOperation(value = "根据ID获取资源")
    @GetMapping("/{id}")
    public R<SysRes> getById(@ApiParam(name = "id", required = true, value = "资源ID") @PathVariable String id) {
        return R.ok(sysResService.getById(id));
    }

    @ApiOperation(value = "新增资源")
    @PostMapping
    public R<Boolean> add(@RequestBody SysRes sysRes) {
        return R.ok(sysResService.save(sysRes));
    }

    @ApiOperation(value = "更新资源")
    @PutMapping
    public R<Boolean> update(@RequestBody SysRes sysRes) {
        return R.ok(sysResService.updateById(sysRes));
    }

    @ApiOperation(value = "删除资源")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@ApiParam(name = "id", required = true, value = "资源ID") @PathVariable String id) {
        return R.ok(sysResService.removeById(id));
    }
} 